<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="12">
			<p-form-item label="采集结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['result', validatorRules.result]" :trigger-change="true" dictCode="" placeholder="请选择采集结果"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename"
						dest-fields="lineid,lineno,linename"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="线体名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="工站" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'workstation', validatorRules.workstation]" placeholder="请输入工站"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mobillno', validatorRules.mobillno]" placeholder="请输入工单编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'qty', validatorRules.qty]" placeholder="请输入数量"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="关键件名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'name', validatorRules.name]" placeholder="请输入关键件名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="关键件条码（旧）" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'bindingFormer', validatorRules.bindingFormer]" placeholder="请输入关键件条码（旧）"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="关键件条码（新）" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'bindingNew', validatorRules.bindingNew]" placeholder="请输入关键件条码（新）"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="替换人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'displacedPerson', validatorRules.displacedPerson]" placeholder="请输入替换人员"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="id,mcode,mname,sprc,mexplain"
						dest-fields="mid,mcode,mname,sprc,mexplain"
						code="wms_cpinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入物料名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="物料规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'sprc', validatorRules.sprc]" placeholder="请输入物料规格型号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mexplain', validatorRules.mexplain]" placeholder="请输入物料描述"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesMfProcessCriticalComponentBindingModal",
	mixins: [SubmitOnchangMixin],
    components: {
      JDictSelectTag,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        result: {},
        lineno: {},
        linename: {},
        workstation: {},
        mobillno: {},
        qty: {},
        name: {},
        bindingFormer: {},
        bindingNew: {},
        displacedPerson: {},
        mcode: {rules: [{ required: true, message: '请输入物料编码!' }]},
        mname: {},
        sprc: {},
        mexplain: {},
        },
        url: {
          add: '/mes-manufacture/auto/mesMfBindingRecord/addMesMfProcessCriticalComponentBinding',
          edit: '/mes-manufacture/auto/mesMfBindingRecord/editMesMfProcessCriticalComponentBinding',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'remark','timestamp','companyId','factoryId','clientId','substituteId','flag','result','lineid','lineno','linename','workstation','moid','mobillno','moautoid','qty','barCode','name','bindingFormer','bindingNew','displacedPerson','createBy','createTime','updateBy','updateTime','mid','mcode','mname','sprc','mexplain','mesMfBindingRecordId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['mesMfBindingRecordId'] = this.mainId
                  this.formData['mesMfBindingRecordId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'remark','timestamp','companyId','factoryId','clientId','substituteId','flag','result','lineid','lineno','linename','workstation','moid','mobillno','moautoid','qty','barCode','name','bindingFormer','bindingNew','displacedPerson','createBy','createTime','updateBy','updateTime','mid','mcode','mname','sprc','mexplain','mesMfBindingRecordId'))
      },


    }
  }
</script>
